home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Gekkan Dennou Club 142
/
Gekkan Dennou Club - 2000.3 Vol. 142 (Japan).7z
/
Gekkan Dennou Club - 2000.3 Vol. 142 (Japan) (Track 1).bin
/
tools
/
s44play
/
s44p101s.lzh
/
buffer.s
< prev
next >
Wrap
Text File
|
2000-01-23
|
5KB
|
241 lines
.include doscall.mac
.include iocscall.mac
.include fefunc.h
.include global.mac
;----------------------------------------------------------------
;バッファを確保する
;>d0.l:0=確保できた,-1=確保できなかった
;>n-flag:mi=確保できなかった
.text
.align 4,$2048
malloc_buffer::
movem.l d1-d2/a0-a3,-(sp)
move.l param_bufunt,bufunt
bpl 10f
;バッファサイズの指定がない
move.l #DEFAULT_BUFUNT,bufunt
tst.b onmem_flag
beq 10f ;-onmemでなければ標準サイズ
malloc_buffer_onmem:
moveq.l #0,d1
tst.b himem_flag
beq @f
bsr himem_exist
bmi @f
moveq.l #3,d1
moveq.l #$F8,d0
trap #15
@@: move.l #$00FFFFFF,-(sp)
DOS _MALLOC
addq.l #4,sp
and.l #$00FFFFFF,d0
cmp.l d1,d0
bcc @f
move.l d1,d0
@@:
;<d0.l:1度に確保できる最大サイズ
tst.b onmem_flag
bne 1f
sub.l #-(16+16+16+16),d0
bra 2f
1: sub.l #-(16+16),d0
2: move.l #BUFSIZ_UNIT,d1
FPACK __UDIV
move.l d0,bufunt
move.l d0,param_bufunt
10:
move.l bufunt,d0
move.l #BUFSIZ_UNIT,d1 ;BUFSIZ_UNIT>65535なのでmulu.wは不可
FPACK __UMUL
movea.l d0,a3
tst.b onmem_flag
bne 1f
lea.l (16+16+16+16,a3),a2 ;アロケートするサイズ
bra 2f
1: lea.l (16+16,a3),a2 ;アロケートするサイズ
2: move.l a2,bufsiz
;<a2.l:アロケートするサイズ
;<a3.l:バッファとして使用するサイズ
tst.b himem_flag
beq 1f ;ハイメモリを使わない
bsr himem_exist
bmi 1f ;ハイメモリが使えない
;ハイメモリからアロケートする
move.l a2,d2
moveq.l #1,d1
moveq.l #$F8,d0
trap #15
tst.l d0
bne 1f ;アロケート失敗
move.l a1,buftop ;アロケートした領域の先頭
adda.l a2,a1
move.l a1,bufbtm ;アロケートした領域の末尾
st.b himem_allocated ;ハイメモリからアロケートした
bra 2f
;普通にアロケートする
1: move.l a2,-(sp)
DOS _MALLOC
addq.l #4,sp
tst.l d0
bpl @f
;アロケートできなかった
tst.l param_bufunt
bpl 80f ;-b<n>の指定があるのでエラー
;-b<n>の指定がないときは確保できる最大のサイズを確保する
bra malloc_buffer_onmem
@@: move.l d0,buftop ;アロケートした領域の先頭
add.l a2,d0
move.l d0,bufbtm ;アロケートした領域の末尾
sf.b himem_allocated ;ハイメモリからアロケートしなかった
2:
move.l a3,d0
move.l #BUFFRM_UNIT,d1
FPACK __UDIV
;<d0.l:バッファとして使用するフレーム数
tst.b onmem_flag
bne 1f
lsr.l #2,d0
bra 2f
1: lsr.l #1,d0
2: cmp.l #65535,d0 ;1度に転送できるフレーム数は65535まで
bls @f
move.l #65535,d0
@@: move.l d0,buffrm
;<d0.l:1個のバッファに使用するフレーム数
move.l #BUFFRM_UNIT,d1
FPACK __UMUL
move.l d0,bufhsiz
;<d0.l:1個のバッファのサイズ
movea.l buftop,a0
move.l a0,buf0top
adda.l d0,a0
move.l a0,buf0btm
lea.l (16,a0),a0 ;ダミー
move.l a0,buf1top
adda.l d0,a0
move.l a0,buf1btm
tst.b onmem_flag
bne 1f
lea.l (16,a0),a0 ;ダミー
move.l a0,buf2top
adda.l d0,a0
move.l a0,buf2btm
lea.l (16,a0),a0 ;ダミー
move.l a0,buf3top
adda.l d0,a0
move.l a0,buf3btm
bra 2f
1: clr.l buf2top ;onmemのときはbuf2,buf3を確保しない
clr.l buf2btm
clr.l buf3top
clr.l buf3btm
2:
tst.b silent_flag
bne @f
lea.l (m_allocated1,pc),a0
bsr eprint
move.l bufsiz,d0
lsr.l #8,d0
lsr.l #2,d0
bsr utos_eprint
lea.l (m_allocated2,pc),a0
bsr eprintcrlf
@@:
98: moveq.l #0,d0
99: movem.l (sp)+,d1-d2/a0-a3
rts
80: move.w #EXIT_MEMORY_ERROR,exit_code
lea.l (m_memory_error,pc),a0
89: bsr eaprintcrlf
moveq.l #-1,d0
bra 99b
m_allocated1: .dc.b 'PCM バッファを ',0
m_allocated2: .dc.b 'KB 確保しました ',0
m_memory_error: .dc.b 'メモリが確保できません',0
.even
.data
.align 4
buftop: .dc.l 0
bufbtm: .dc.l 0
stpfrm:: .dc.l DEFAULT_BUFFRM
stpsiz:: .dc.l DEFAULT_BUFSIZ
.bss
.align 4
bufunt: .ds.l 1
bufsiz: .ds.l 1
buffrm:: .ds.l 1
bufhsiz:: .ds.l 1
buf0top:: .ds.l 1
buf0btm: .ds.l 1
buf1top:: .ds.l 1
buf1btm: .ds.l 1
buf2top:: .ds.l 1
buf2btm: .ds.l 1
buf3top:: .ds.l 1
buf3btm: .ds.l 1
himem_allocated: .dc.b 0
;----------------------------------------------------------------
;ハイメモリが使えるかどうか調べる
;>d0.l:0=使える,-1=使えない
;>n-flag:mi=使えない
.text
.align 4,$2048
himem_exist:
move.l a1,-(sp)
move.w #$01F8,-(sp)
DOS _INTVCG
addq.l #2,sp
movea.l d0,a1
subq.l #6,a1
IOCS _B_LPEEK
cmp.l #'HIME',d0
bne 90f ;ハイメモリが使えない
IOCS _B_WPEEK
cmp.w #'M'*$0100,d0
bne 90f ;ハイメモリが使えない
moveq.l #0,d0
99: movea.l (sp)+,a1
rts
90: moveq.l #-1,d0
bra 99b
;----------------------------------------------------------------
;バッファを開放する
.text
.align 4,$2048
free_buffer::
move.l buftop,d0
beq 9f
tst.b himem_allocated
beq 1f
move.l d0,d2
moveq.l #2,d1
moveq.l #$F8,d0
trap #15
bra 2f
1: move.l d0,-(sp)
DOS _MFREE
addq.l #4,sp
2: clr.l buftop
clr.l bufbtm
sf.b himem_allocated
9: moveq.l #0,d0
rts